﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sheeps
{
    /// <summary>
    /// Represents game or simulation
    /// </summary>
    public class Game
    {
        private SheepGenerator generator;

        /// <summary>
        /// Current state
        /// </summary>
        public GameState State
        {
            get;
            protected set;
        }

        /// <summary>
        /// Algorithm used to control dog
        /// </summary>
        public DogBehaviorAlogorithm DogAlgorithm
        {
            get;
            set;
        }

        /// <summary>
        /// Algorithm used to control sheep
        /// </summary>
        protected SheepBehaviorAlogorithm SheepAlgorithm
        {
            get;
            set;
        }

        /// <summary>
        /// Goes next step of simulation. First calulates position of dog, then positions of sheep
        /// </summary>
        public void NextStep()
        {
            this.DogAlgorithm.UpdatePositions(this.State);
            this.SheepAlgorithm.UpdatePositions(this.State);
        }

        /// <summary>
        /// Places sheep and dog on pasture
        /// </summary>
        /// <param name="count">Count of sheep to place</param>
        public void GenerateSheep(int count)
        {
            this.generator.GenerateSheep(this.State, count);
            this.generator.GenerateDog(this.State);
        }
        
        /// <summary>
        /// Creates new instance of Game
        /// </summary>
        /// <param name="dogAlgorithm">Algorithm to control dog</param>
        /// <param name="sheepAlgorithm">Algorithm to control sheep</param>
        /// <param name="generator">Sheep and dog generator object</param>
        /// <param name="width">Pasture width</param>
        /// <param name="height">Pasture height</param>
        public Game(DogBehaviorAlogorithm dogAlgorithm, SheepBehaviorAlogorithm sheepAlgorithm,
            SheepGenerator generator,
            double width, double height)
        {
            this.State = new GameState(width, height);
            this.DogAlgorithm = dogAlgorithm;
            this.SheepAlgorithm = sheepAlgorithm;
            this.generator = generator;
        }
    }
}
